Skip to content

Preserve FCM token after service worker reset (version tap)#187

Merged
ProLoser merged 3 commits intomainfrom
copilot/fix-notification-token-deletion
Mar 21, 2026
Merged

Preserve FCM token after service worker reset (version tap)#187
ProLoser merged 3 commits intomainfrom
copilot/fix-notification-token-deletion

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 20, 2026

  • Fix Friends.tsx to auto-save FCM token when permission is already 'granted' but the current token is missing from Firebase (covers the case after a version reset clears the service worker)
  • Guard against falsy token from getFcmToken() before calling snapshot.child(token)
Original prompt

tapping the version number to update is deleting the notification token and disabling people's notification accidentally. I want you to preserve the notification setting when resetting everything else if possible or resetting and then rewriting the notification token back


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: ProLoser <67395+ProLoser@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix version update logic to preserve notification token Preserve FCM token after service worker reset (version tap) Mar 20, 2026
Copilot AI requested a review from ProLoser March 20, 2026 01:14
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 20, 2026

PR Preview Action v1.8.1
Preview removed because the pull request was closed.
2026-03-21 22:10 UTC

@ProLoser ProLoser marked this pull request as ready for review March 21, 2026 19:09
@ProLoser ProLoser requested a review from Copilot March 21, 2026 19:09
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adjusts FCM token persistence logic so users who already granted notifications don’t silently lose notifications after a service worker reset (e.g., via “version tap” unregistering SW and rotating the FCM token).

Changes:

  • Broaden token auto-save condition to run when notification permission is not 'denied' (including 'granted'), so rotated tokens get re-written to Firebase.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +108 to 110
// Also re-save on 'granted' in case the service worker was refreshed (e.g. version reset)
if (window.Notification?.permission !== 'denied')
tokensRef.once('value', snapshot => snapshot.child(token).exists() || saveFcmToken())
Copy link

Copilot AI Mar 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getFcmToken() can resolve with a falsy token (e.g. null) when Messaging can't provide one yet. In that case snapshot.child(token) will throw and break this effect. Guard against a missing token before calling .child(...) (and decide whether you want to call saveFcmToken() when token is missing).

Copilot uses AI. Check for mistakes.
@ProLoser
Copy link
Copy Markdown
Owner

@copilot address feedback

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Mar 21, 2026

@copilot address feedback

Added the guard in 561d67a — the condition is now if (token && window.Notification?.permission !== 'denied') so snapshot.child(token) is only called when token is truthy.

Copilot AI requested a review from ProLoser March 21, 2026 19:16
@ProLoser ProLoser merged commit 8cdbb87 into main Mar 21, 2026
@ProLoser ProLoser deleted the copilot/fix-notification-token-deletion branch March 21, 2026 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants